<?php

namespace App\Console\Commands;

use App\Models\Config;
use App\Models\Design;
use Illuminate\Console\Command;

class FillData2 extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'fill:data2';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '填充数据';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        Config::query()->create([
            'key'  => 'designIntegral',
            'name' => '生成刘海壁纸积分',
            'val'  => '6'
        ]);

        Config::query()->create([
            'key'  => 'templateId',
            'name' => '订阅消息模板ID',
            'val'  => ''
        ]);

        Design::query()->truncate();
        $json = json_decode(file_get_contents(public_path('db_init.json')), true);
        $wx_design = $json['wx_design']['data'];
        $design = [];
        foreach ($wx_design as $item) {
            $design[] = [
                'image' => $item['image'],
                'mode'  => $item['mode'],
                'created_at' => now(),
                'updated_at' => now(),
            ];
        }
        Design::query()->insert($design);

        return 0;
    }
}
